<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 *
 * base_url/admin
 *
 * @package    controllers
 * @author     Bertrand Kintanar <bertrand.kintanar@gmail.com>
 * @version    $Id: index.php 214 2011-12-08 21:01:26Z bertrand.kintanar@gmail.com $
 * @copyright  &copy; 2011 NaCl.org WebGroup
 *
 */
class Index extends MY_Controller {

    
    public function __construct()
    {
        parent::__construct();
        parent::_get_script(__FILE__);

        // make sure that the user is logged in before they could see the page
        if(!$this->tank_auth->is_logged_in())
        {
            redirect('/auth/login');
        }
    }
    
    public function index()
    {
        $_user_id = $this->tank_auth->get_user_id();

        $_user_obj    = new \models\User;
        $_church_obj  = new \models\Church;
        $_section_obj = new \models\Section;
        $_address_obj = new \models\Address;
        $_social_obj  = new \models\Social;
        $_s_type_obj  = new \models\SocialType;
        
        // get models needed for view
        $_user      = $_user_obj->getUserById($_user_id);
        $_p_profile = $_user->pastor_profile;
        $_church    = $_church_obj->getChurchById($_p_profile->church_id);
        $_section   = $_section_obj->getSectionById($_church->section_id);
        $_address   = $_address_obj->getAddressById($_church->address_id);
        $_socials   = $_social_obj->getSocialsByChurchId($_church->church_id);
        $_s_types   = $_s_type_obj->getSocialTypes();

        $this->smarty->assign('user', $_user);
        $this->smarty->assign('church', $_church);
        $this->smarty->assign('section', $_section);
        $this->smarty->assign('address', $_address);
        $this->smarty->assign('socials', $_socials);

        $this->smarty->assign('load_modal', true);
        $this->smarty->assign('load_forms', true);

        $this->smarty->assign('main_content', 'admin/index.tpl');
        $this->smarty->view();
    }
}
